<template>
  <div class="app-container">
    <el-form
      ref="queryForm"
      :model="queryParams"
      size="small"
      :inline="true"
      label-width="68px"
    >
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="getList"
        >
          刷新
        </el-button>
      </el-form-item>
    </el-form>

    <el-table v-loading="loading" :data="sessionList">
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="序号" align="center" type="index" />
      <el-table-column label="用户名称" align="center" prop="customerName" />
      <el-table-column label="未读数" align="center" prop="unreadNum" />
      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
      >
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['system:session:getInfo']"
            size="mini"
            type="text"
            icon="el-icon-delete"
            @click="getMessageList(scope.row)"
          >
            回复
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 回复对话框 -->
    <Dialogue 
      v-if="dialogSession" 
      v-model="dialogSession" 
      :customer="customer"
     />
  </div>
</template>

<script>
import { listSession} from "@/api/system/session";
import Dialogue from './Dialogue.vue'

export default {
  name: "Session",
  components: {
    Dialogue
  },
  data() {
    return {
      loading: true,
      total: 0,
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        sendingCustomerId: null,
        receivedCustomerId: null,
        content: null,
        state: null,
      },
      sessionList: [],
      dialogSession: false,
      customer: {},
    };
  },
  created() {
    this.getList();
  },
  methods: {
    getList() {
      this.loading = true;
      listSession(this.queryParams).then((response) => {
        this.sessionList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 打开回复弹窗，获取会话列表
    getMessageList(row) {
      this.customer = {name: row.customerName, id: row.customerId}
      this.dialogSession = true;
    },
  },
};
</script>
<style scoped lang="scss">

</style>
